package com.twu.biblioteca;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Raluca Puichilita on 01/08/2014.
 */

public class BookManager {

    public static List<Book> collectionOfAvailableBooks = new ArrayList<Book>();
    public static List<Book> collectionOfUnavailableBooks = new ArrayList<Book>();

    protected static void populateListWithBooks() {
        collectionOfAvailableBooks.add(new Book("The Great Gatsby", "F. Scott Fitzgerald", 1925));
        collectionOfAvailableBooks.add(new Book("The Grapes of Wrath", "John Steinbeck", 1939));
        collectionOfAvailableBooks.add(new Book("Nineteen Eighty-Four", "George Orwell", 1949));
        collectionOfAvailableBooks.add(new Book("Ulysses", "James Joyce", 1918));
        collectionOfAvailableBooks.add(new Book("Lolita", "Vladimir Nabokov", 1955));
        collectionOfAvailableBooks.add(new Book("The Catcher in the Rye", "J.D. Salinger", 1951));
    }

    protected static void listAllBooksFromCollection(List<Book> bookList) {
        if (bookList.size() < 1)
            System.out.println("The are no available books. Please try again later.");
        else
            for (Book thisBook : bookList) {
                System.out.print("(" + (bookList.indexOf(thisBook) + 1) + ") ");
                System.out.println(thisBook);
            }
    }

    protected static void checkOutBook(int choice) {
        Book thisBook = collectionOfAvailableBooks.get(choice-1);
        collectionOfAvailableBooks.remove(thisBook);
        collectionOfUnavailableBooks.add(thisBook);
        System.out.print("\n" + thisBook + " has been successfully checked out!\n");
    }

    protected static void returnBook(int choice) {
        Book thisBook = collectionOfUnavailableBooks.get(choice-1);
        collectionOfAvailableBooks.add(thisBook);
        collectionOfUnavailableBooks.remove(thisBook);
        System.out.print("\n" + thisBook + " has been successfully returned!\n");
    }

}
